package com.turman.composebook

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.turman.composebook.ui.theme.ComposeBookTheme
import com.turman.composebook.views.MainPage
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.net.InetAddress
import java.net.NetworkInterface

class MainActivity : ComponentActivity() {
    private val deviceIps:MutableMap<String,String> = mutableMapOf()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MainPage()
        }

//        checkIps()
    }

//    fun checkIps() {
//        GlobalScope.launch(Dispatchers.IO) {
//            val interfaces = NetworkInterface.getNetworkInterfaces()
//            while (interfaces.hasMoreElements()) {
//                val networkInterface = interfaces.nextElement()
//                val addresses = networkInterface.inetAddresses
//                while (addresses.hasMoreElements()) {
//                    val address = addresses.nextElement()
//                    if (!address.isLoopbackAddress && address.isSiteLocalAddress) {
//                        Log.i("address",address.hostAddress)
//                        deviceIps[address.hostAddress] = address.hostName
//                    }
//                }
//            }
//
//            var host = InetAddress.getByName("192.168.1.113")
//            var result = host.isReachable(3000)
//            Log.i("address","${host.hostName} $result")
//            host = InetAddress.getByName("192.168.0.201")
//            result = host.isReachable(3000)
//            Log.i("address","${host.hostName} $result")
//        }
//    }
}